﻿    using SuporeSliplampApp.Models;
    using SuporeSliplampApp.Util;
    using SuporeSliplampApp.ViewModels;
    using SuporeSliplampApp.Views;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;

    namespace SuporeSliplampApp.Control
    {
        /// <summary>
        /// ScrollControl.xaml 的交互逻辑
        /// </summary>
        public partial class ScrollControl : UserControl
        {
            ~ScrollControl()
            {
                Debug.WriteLine($"ScrollControl {this.GetHashCode()} finalized");
            }


            public static event EventHandler<ListControlModel> scrollDelegate;
            public static event EventHandler<VideoModel> videoDelegate;

            private double selectedMultiplier;
            private int osodindex;

            public bool IsMyChecked
            {
                get { return (bool)GetValue(IsMyCheckedProperty); }
                set
                {
                    SetValue(IsMyCheckedProperty, value);
                }
            }

            // Using a DependencyProperty as the backing store for IsMyChecked.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty IsMyCheckedProperty =
                DependencyProperty.Register("IsMyChecked", typeof(bool), typeof(ScrollControl), new PropertyMetadata(false, new PropertyChangedCallback(OnMyPropertyChanged)));

            private static void OnMyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                CheckBox c = d as CheckBox;

            }

            public string MyPicPath
            {
                get { return (string)GetValue(MyPicPathProperty); }
                set { SetValue(MyPicPathProperty, value); }
            }

            // Using a DependencyProperty as the backing store for MyPicPath.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty MyPicPathProperty =
                DependencyProperty.Register("MyPicPath", typeof(string), typeof(ScrollControl), new PropertyMetadata(null));




            public ScrollControl()
            {
                InitializeComponent();

                var model = new ScrollControlViewModel();
                DataContext = model;
                CamaraView.openImageDelegate += CamaraView_openImageDelegate;

            }

            private void CamaraView_openImageDelegate(object sender, string e)
            {
                throw new NotImplementedException();
            }

            private void But_MouseDoubleClick(object sender, MouseButtonEventArgs e)
            {

            }

            private void confirmBtn_Click(object sender, RoutedEventArgs e)
            {

            }

            private void cancelBtn_Click(object sender, RoutedEventArgs e)
            {

            }


            private void StackPanel_MouseDown_1(object sender, MouseButtonEventArgs e)
            {
                // MessageBox.Show("test");
                var st = sender as StackPanel;
                ListControlModel dt = st.DataContext as ListControlModel;
                VideoModel video = st.DataContext as VideoModel;
            

                if (dt == null)
                {
                    videoDelegate?.Invoke(this,video);
                }
                else
                {
                    //dt.Multiplier = selectedMultiplier;
                    //dt.osodIndex = osodindex;
                    MyPicPath = dt.ImgPath;
                    scrollDelegate?.Invoke(this, dt);
                }



            }

            private void CheckBox_Checked(object sender, RoutedEventArgs e)
            {
                if (myCheckBox.IsChecked == false)
                {
                    IsMyChecked = false;
                }
                else
                {
                    IsMyChecked = true;
                }

            }

            private void CheckBox_UnChecked(object sender, RoutedEventArgs e)
            {
                if (myCheckBox.IsChecked == false)
                {
                    IsMyChecked = false;
                }
                else
                {
                    IsMyChecked = true;
                }

            }

            /// <summary>
            /// 释放图像资源
            /// </summary>


            /// <summary>
            /// 辅助方法：查找所有可视化子元素
            /// </summary>

        }
    }

